﻿using System;
using System.Linq;
using System.Web.Mvc;
using System.Web.Security;
using CMSMVC4.Filters;

namespace CMSMVC4.Areas.Admin.Controllers
{
    // Camnv
    //[Authorize(Roles = "Admin")]
    public class MenusController : Controller
    {
        CMSMVC4Entities _db = new CMSMVC4Entities();
        CommandSql cmd = new CommandSql();

        /// <summary>
        /// Lấy danh sách menu
        /// </summary>
        /// <returns>
        /// Area = 0
        /// </returns>
        [ChildActionOnly]
        public  ActionResult ListLoadMenuParrent(string id)
        {
            ViewBag.ID = id;
            string role = "";
            var ac = _db.Accounts.FirstOrDefault(x => x.Account1.Equals(User.Identity.Name));
            if (ac != null)
            {
                role = ac.Role;
            }
            var data = cmd.GetMenuParrent(MenuArea.Admin,role);
            return PartialView(data);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [ChildActionOnly]
        public  ActionResult CountMenuChild(string parrent)
        {
            var data = _db.Menus.Where(x => x.Type == MenuArea.Admin && x.Parrent == Convert.ToInt32(parrent)).ToList();
            return PartialView(data.Count);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="parrent"></param>
        /// <returns></returns>
        [ChildActionOnly]
        public ActionResult ListLoadMenuChild(string parrent)
        {
            var data = cmd.GetMenuChil(Convert.ToInt32(parrent), MenuArea.Admin);
            return PartialView(data);
        }
    }
}
